#include <cmath>
#include <iostream>

using namespace std;
typedef long long ll;
void exgcd(ll a, ll b, ll& d, ll& x, ll& y) {
  if (b == 0) {
    d = a;
    x = 1;
    y = 0;
  } else {
    exgcd(b, a % b, d, y, x);
    y -= x * (a / b);
  }
}
int main() {
  ll a, b, c, k;
  while (cin >> a >> b >> c >> k) {
    if (a == 0 && b == 0 && c == 0 && k == 0) break;
    ll r = b - a, d, x, y;
    exgcd(c, (ll)1 << k, d, x, y);
    if (r % d) {
      cout << "FOREVER" << endl;
      continue;
    }
    x *= r / d;
    ll m = ((ll)1 << k) / d;
    x = (x % m + m) % m;
    cout << x << endl;
  }
  return 0;
}
